<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" autoFlush="false" buffer="1028kb"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<c:set var="v" value="${TIME}" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="${ctx}/resource/plugins/encrypt/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="${ctx}/resource/plugins/encrypt/md5.js"></script>
<script type="text/javascript" src="${ctx}/resource/plugins/encrypt/jsbn.js"></script>
<script type="text/javascript" src="${ctx}/resource/plugins/encrypt/prng4.js"></script>
<script type="text/javascript" src="${ctx}/resource/plugins/encrypt/rng.js"></script>
<script type="text/javascript" src="${ctx}/resource/plugins/encrypt/rsa.js"></script>
<script type="text/javascript" src="${ctx}/resource/plugins/encrypt/base64.js?v=${v}"></script>
<style type="text/css">
body * {padding: 5px;}
textarea,button{border: 1px solid #C7C7CB;}
textarea {width: 99%;}
table {border: none;width: 100%;}
sub{font-size: 10px;color: #989898;}
</style>
</head>
<body>
	<h3>RSA加解密：  js加密，java解密<sub>[没有使用分段加密,可用于 密码、短文本 加密]</sub></h3>
	 
	<table cellpadding="0" cellspacing="0">
		<tr>
			<td width="100px">原文：</td>
			<td><textarea id="value" rows="3" cols="">你努力，但你不在风口上。你聪明，但你不在潮流中。</textarea></td>
		</tr>
		<tr>
			<td>Base64：</td>
			<td><textarea id="jsBase64Value" rows="3" cols=""></textarea></td>
		</tr>
		<tr>
			<td>Js-RSA：</td>
			<td><textarea id="jsRSAValue" rows="3" cols=""></textarea></td>
		</tr>
		<tr>
			<td colspan="2"><button type="button" onclick="doJsRSA()">执行加密</button></td>
		</tr>
		<tr>
			<td>Java-RSA：</td>
			<td><textarea id="javaValue" rows="3" cols=""></textarea></td>
		</tr>
		<tr>
			<td colspan="2"><button type="button" onclick="doJavaRSA()">执行解密</button></td>
		</tr>
	</table>
	<script type="text/javascript">
		var encryptionExponent = "${encryptionExponent}";
		var modulus = "${modulus}";
		//js RSA加密
		function doJsRSA() {
			alert("开始加密");
			//1、初始化
			var rsa = new RSAKey();
			//2、设置密钥 [从后端获取] 
			rsa.setPublic(modulus, encryptionExponent);
			//3、Base64加密[防止中文乱码] 
			var value = new Base64().encode($("#value").val());
			//4、执行加密 
			var jsRSAValue = rsa.encrypt(value);

			$("#jsBase64Value").val(value);
			$("#jsRSAValue").val(jsRSAValue);
			alert("JS RSA加密完成 ");
		}
		//java 解密 
		function doJavaRSA() {
			alert("开始解密"); 
			$.ajax({
				cache : false,
				type : "post",
				url : "${ctx}/test/rsa/rsaDecry?timestamp=" + new Date().getTime(),
				data : {
					value : $("#jsRSAValue").val()
				},
				traditional : true,
				success : function(data) {
					alert("解密完成");
					$("#javaValue").val(data);
				}
			});
		}
	</script>
</body>
</html>